package com.lkd.controller;

import com.lkd.dto.VmTypeDto;
import com.lkd.entity.VmType;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.VmTypeService;
import com.lkd.vo.VmTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/vmType")
public class VmTypeController {

    @Autowired
    private VmTypeService vmTypeService;

    /**
     * 分页查询设备
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/search")
    public Result<PageBean<VmTypeVo>> findByPage(
            @RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "name", required = false) String name
    ){
        PageBean<VmTypeVo> pageBean = vmTypeService.findByPage(pageIndex,pageSize,name);
        return Result.success(pageBean);
    }

    /**
     * 新增设备类型
     * @param dto
     * @return
     */
    @PostMapping
    public Result save(@RequestBody VmTypeDto dto){
        vmTypeService.save(dto);
        return Result.success();
    }

    /**
     * 修改设备类型
     * @param dto
     * @return
     */
    @PutMapping
    public Result update(@RequestBody VmTypeDto dto){
        vmTypeService.update(dto);
        return Result.success();
    }

    /**
     * 删除设备类型
     * @param typeId
     * @return
     */
    @DeleteMapping("/{typeId}")
    public Result delete(@PathVariable(name = "typeId") Integer typeId){
        vmTypeService.delete(typeId);
        return Result.success();
    }
}
